﻿//https://leetcode.cn/problems/time-needed-to-buy-tickets/submissions/604832061/?envType=problem-list-v2&envId=queue

class Solution {
public:
    int timeRequiredToBuy(vector<int>& tickets, int k)
    {
        int n = tickets.size();
        int ret = 0;
        int i = 0;
        while (tickets[k])
        {
            if (tickets[i % n] > 0)
            {
                tickets[i % n]--;
                ret++;
            }
            i++;
        }
        return ret;
    }
};
